package com.yserp.project.erp.bill.receivemoney.controller;

import com.yserp.common.utils.poi.ExcelUtil;
import com.yserp.framework.aspectj.lang.annotation.Log;
import com.yserp.framework.aspectj.lang.enums.BusinessType;
import com.yserp.framework.web.controller.BaseController;
import com.yserp.framework.web.domain.AjaxResult;
import com.yserp.framework.web.page.TableDataInfo;
import com.yserp.project.erp.bill.receivemoney.domain.ReceiveMoneyItem;
import com.yserp.project.erp.bill.receivemoney.service.IReceiveMoneyItemService;
import com.yserp.project.erp.order.saleorder.domain.ErpSaleOrder;
import com.yserp.project.erp.order.saleorder.service.IErpSaleOrderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 收款单Controller
 * 
 * @author yserp
 * @date 2022-08-11
 */
@Controller
@RequestMapping("/bill/receivemoney/item")
public class ReceiveMoneyItemController extends BaseController
{
    private String prefix = "erp/bill/receivemoney";

    @Autowired
    private IReceiveMoneyItemService receiveMoneyItemService;
    @Autowired
    private IErpSaleOrderService saleOrderService;

    @RequiresPermissions("bill:receivemoney:view")
    @GetMapping()
    public String receivemoney()
    {
        return prefix + "/receivemoney";
    }

    /**
     * 查询收款单列表
     */
    @RequiresPermissions("bill:receivemoney:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReceiveMoneyItem receiveMoneyItem)
    {
        startPage();
        List<ReceiveMoneyItem> list = receiveMoneyItemService.selectReceiveMoneyItemList(receiveMoneyItem);
        return getDataTable(list);
    }

    /**
     * 导出收款单列表
     */
    @RequiresPermissions("bill:receivemoney:export")
    @Log(title = "收款单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ReceiveMoneyItem receiveMoneyItem)
    {
        List<ReceiveMoneyItem> list = receiveMoneyItemService.selectReceiveMoneyItemList(receiveMoneyItem);
        ExcelUtil<ReceiveMoneyItem> util = new ExcelUtil<ReceiveMoneyItem>(ReceiveMoneyItem.class);
        return util.exportExcel(list, "收款单数据");
    }

    /**
     * 根据客户id获取收款订单列表
     */
    @PostMapping("/selectSaleOrderAjaxList")
    @ResponseBody
    public AjaxResult selectSaleOrderAjaxList(ErpSaleOrder saleOrder) {
        List<ReceiveMoneyItem> mapList = saleOrderService.selectSaleOrderListByCustomerId(saleOrder.getCustomerId());
        return AjaxResult.success(mapList);
    }


}
